package com.book.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.book.model.dto.UniverQueryDTO;
import com.book.model.entity.University;
import com.book.mapper.UniversityMapper;
import com.book.service.UniversityService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * <p>
 * 学校信息 服务实现类
 * </p>
 *
 * @author auto
 * @since 2025-04-11 09:30:34
 */
@Service
public class UniversityServiceImpl extends ServiceImpl<UniversityMapper, University> implements UniversityService {

    @Override
    public Page<University> getUniversityListByPage(UniverQueryDTO dto) {
        Page<University> universityPage = new Page<>(dto.getPage(), dto.getSize());
        LambdaQueryWrapper<University> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.like(StringUtils.isNotBlank(dto.getName()),University::getUniverName, dto.getName());
        Page<University> resultPage = this.page(universityPage,queryWrapper);
        return resultPage;
    }

    @Override
    public University addUniversity(University university) {
        if (StringUtils.isNotBlank(university.getUniverId())){
            university.setCreateTime(new Date());
        }
        this.saveOrUpdate(university);
        return university;
    }
}
